<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="css/login.css"/>
    <script src="/js/ajax.js"></script>
</head>
<body>
    <div class="container">
        <div id="login">
            <div class="title">欢迎注册会员</div>
            <form action="">
                <div class="content">
                    <div class="row form-group">
                        <div class="col-xs-4 col-md-4">
                            <label for="">用户名:</label>
                        </div>
                        <div class="col-xs-8 col-md-8"><input type="text" id="username"></div>
                    </div>
                    <div class="row form-group">
                        <div class="col-xs-4 col-md-4">
                            <label for="">密码:</label>
                        </div>
                        <div class="col-xs-8 col-md-8"><input type="password" id="password"></div>
                    </div>
                    <div class="row form-group">
                        <div class="col-xs-4 col-md-4">
                            <label for="">确认密码:</label>
                        </div>
                        <div class="col-xs-8 col-md-8"><input type="password" id="repassword"></div>
                    </div>
                    <div class="row form-group btn-wrap">
                        <button id="reg" type="button" class="btn btn-danger">注册</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <script>
        var oIpt1 = document.getElementById("username")
		var oIpt2 = document.getElementById("password")
		var oIpt3 = document.getElementById("repassword")
		var oBtn = document.getElementById("reg")
		oBtn.onclick = function  () {
			if (oIpt2.value === oIpt3.value) {
				var opt = {
								method : "post",
								url : '/user_register',
								data : "username="+oIpt1.value+"&password="+oIpt2.value,
								success : function  (data) {
									console.log(data);
									if(data.status === 0){
										window.location.href = "/login.html";
									}else{
										alert(data.message);
									}
								}
							};
				ajax(opt);
			} else{
				alert("两次密码不一致！")
			}
		}
    </script>
</body>
</html>